package cn.sstech.IM.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;


import cn.sstech.IM.constant.Constants;
import cn.sstech.IM.rebot.proxy.impl.MLRebotProxy;
import cn.sstech.IM.server.ImServer;
import cn.sstech.IM.server.ImWebsocketServer;
import cn.sstech.IM.server.connertor.impl.ImConnertorImpl;
import cn.sstech.IM.server.group.BroadcastGroupManager;
import cn.sstech.IM.server.proxy.impl.MessageProxyImpl;
import cn.sstech.IM.server.session.impl.SessionManagerImpl;

/**
 * 上面代码创建了一个SqlSessionFactory和一个SqlSessionTemplate，为了支持注解事务，增加了@EnableTransactionManagement注解，
 * 并且反回了一个PlatformTransactionManagerBean。
 * @author Administrator
 *
 */
@Configuration
public class InitIMConfig{
	
    @Bean(value="rebotProxy")
    public MLRebotProxy mLRebotProxy() {
    	MLRebotProxy mLRebotProxy = new MLRebotProxy();
    	mLRebotProxy.setApiUrl("http://i.itpk.cn/api.php");
    	mLRebotProxy.setKey("");
    	mLRebotProxy.setSecret("");
    	return mLRebotProxy;
    }
    
    @Bean(value="connertor")
    public ImConnertorImpl imConnertorImpl() {
    	ImConnertorImpl imConnertorImpl = new ImConnertorImpl();
    	imConnertorImpl.setSessionManager(sessionManagerImpl());
    	imConnertorImpl.setProxy(messageProxyImpl());
    	return imConnertorImpl;
    }
    
    @Bean(value="proxy")
    public MessageProxyImpl messageProxyImpl() {
    	MessageProxyImpl messageProxyImpl = new MessageProxyImpl();
    	messageProxyImpl.setRebotProxy(mLRebotProxy());
    	return messageProxyImpl;
    }
    
    @Bean(value="imServer",initMethod="init",destroyMethod="destroy")
    public ImServer imServer() {
    	ImServer imserver = new ImServer();
    	imserver.setPort(Constants.ImServerInit.imServerPort);
    	imserver.setConnertor(imConnertorImpl());
    	imserver.setProxy(messageProxyImpl());
    	return imserver;
    }
    
    @Bean(value="imWebsocketServer",initMethod="init",destroyMethod="destroy")
    public ImWebsocketServer imWebsocketServer() {
    	ImWebsocketServer imWebsocketServer = new ImWebsocketServer();
    	imWebsocketServer.setPort(Constants.ImServerInit.imWebsocketServerPort);
    	imWebsocketServer.setConnertor(imConnertorImpl());
    	imWebsocketServer.setProxy(messageProxyImpl());
    	return imWebsocketServer;
    }
    
    @Bean(value="sessionManager")
    public SessionManagerImpl sessionManagerImpl() {
    	SessionManagerImpl sessionManagerImpl = new SessionManagerImpl();
    	sessionManagerImpl.setProxy(messageProxyImpl());
    	return sessionManagerImpl;
    }
    
    @Bean(value="broadcastGroupManager",initMethod="init")
    public BroadcastGroupManager broadcastGroupManager(){
    	BroadcastGroupManager broadcastGroupManager = new BroadcastGroupManager();
    	return broadcastGroupManager;
    }


}
